package com.example.learn.utile;

import com.example.learn.entity.Expenditure;
import com.example.learn.entity.Income;

import java.util.*;

public class charutile {
    public static List<String> getcharYear(List<Income> incomeList, String year) {
        List<String> stringList = new ArrayList<>();
        Map<String, Double> map = new LinkedHashMap<String, Double>();
        map.put(year+"-01",0.0);
        map.put(year+"-02",0.0);
        map.put(year+"-03",0.0);
        map.put(year+"-04",0.0);
        map.put(year+"-05",0.0);
        map.put(year+"-06",0.0);
        map.put(year+"-07",0.0);
        map.put(year+"-08",0.0);
        map.put(year+"-09",0.0);
        map.put(year+"-10",0.0);
        map.put(year+"-11",0.0);
        map.put(year+"-12",0.0);


        for (Income income : incomeList
        ) {
            if (income.getDate().equals(year + "-01")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-02")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-03")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-04")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-05")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-06")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-07")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-08")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-09")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-10")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-11")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-12")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
        }

        map.forEach((key, value) -> {
            stringList.add(value.toString());
        });
        return stringList;
    }
    public static List<String> getcharYear2(List<Expenditure> incomeList, String year) {
        List<String> stringList = new ArrayList<>();
        Map<String, Double> map = new LinkedHashMap<String, Double>();
        map.put(year+"-01",0.0);
        map.put(year+"-02",0.0);
        map.put(year+"-03",0.0);
        map.put(year+"-04",0.0);
        map.put(year+"-05",0.0);
        map.put(year+"-06",0.0);
        map.put(year+"-07",0.0);
        map.put(year+"-08",0.0);
        map.put(year+"-09",0.0);
        map.put(year+"-10",0.0);
        map.put(year+"-11",0.0);
        map.put(year+"-12",0.0);


        for (Expenditure income : incomeList
        ) {
            if (income.getDate().equals(year + "-01")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-02")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-03")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-04")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-05")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-06")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-07")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-08")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-09")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-10")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-11")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
            if (income.getDate().equals(year + "-12")) {
                Double value = 0.0;
                if (map.keySet().contains(income.getDate())) {
                    value = map.get(income.getDate()) + income.getMoney();
                    map.put(income.getDate(), value);
                } else {
                    value = income.getMoney();
                    map.put(income.getDate(), value);
                }
            }
        }

        map.forEach((key, value) -> {
            stringList.add(value.toString());
        });
        return stringList;
    }
}
